#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<unordered_map>
using namespace std;
class Solution {
public:
    int totalFruit(vector<int>& fruits)
    {
        int len = -1;
        unordered_map<int, int> m;
        for (int begin = 0, end = 0; end < fruits.size(); end++)
        {
            m[fruits[end]]++;
            while (m.size() > 2)
                if ((--m[fruits[begin++]]) == 0) m.erase(fruits[begin - 1]);
            len = max(len, end - begin + 1);
        }
        return len;
    }
};
int main()
{

	return 0;
}